#!/bin/bash
scriptWorkd=$(cd "$(dirname $0)";pwd)
root_Workd=${scriptWorkd}/..

### ========= 全局变量 ===========
### ==============================

### ========= 前置文件 ===========
if [[ -f ${HOME}/bin/basic_func.sh ]];then  ### 存在才载入
    source ${HOME}/bin/basic_func.sh
elif [[ -f ${scriptWorkd}/../bin/basic_func.sh ]];then
    source ${scriptWorkd}/../bin/basic_func.sh
elif [[ -f ./bin/basic_func.sh ]];then
    source ./bin/basic_func.sh
fi
### ==============================

function install-fonts() {
set -e
    lastdir=$(pwd)
    mkdir -p ${HOME}/Downloads/fonts/temp
    cd ${HOME}/Downloads/fonts/temp

    githubDownload microsoft/cascadia-code/releases/download/v2404.23/CascadiaCode-2404.23.zip
    githubDownload JetBrains/JetBrainsMono/releases/download/v2.304/JetBrainsMono-2.304.zip
    git clone https://gitee.com/mitnickhou/fonts

    unzip CascadiaCode-2404.23.zip -d cas
    unzip JetBrainsMono-2.304.zip -d jet

    sudo mkdir -p /usr/share/fonts/jet
    sudo mkdir -p /usr/share/fonts/cas
    sudo mkdir -p /usr/share/fonts/opposans

    sudo cp -r ./jet/fonts/ttf /usr/share/fonts/jet/
    sudo cp -r ./cas/ttf /usr/share/fonts/cas/
    sudo rsync -av --exclude='.git' --exclude='README.md' --exclude='README.en.md' ./fonts/ /usr/share/fonts/other/

    sudo mkfontscale
    sudo mkfontdir
    sudo fc-cache -fv
    cd ${lastdir}
    # rm -rf ./temp
    unset lastdir
}

function main() {
set -e
    ## 开始信息
    echo -e "${blue4}\n$(basename $0)\n${normal}"

    sudo apt install -y rsync
    install-fonts
    echo -e "${hintStrSucceed}\nFont installed\n字体安装完成${normal}\n"

    ## 结束信息
    echo -e "${green4}\n$(basename $0)\n${normal}"
}
main $@
